<?php
/*
 * 自动加载路由
 * 规则：controller目录下的php文件为一个路由页面
 */
function loadUrls($dir_path)
{
    $dirs = array('');
    $url_maps = array();
    while (!empty($dirs)) {
        $current = array_pop($dirs);
        if ($handle = opendir($dir_path . '/' . $current)) {
            while (false !== ($file = readdir($handle))) {
                if ($file == "." || $file == "..")
                    continue;
                if (is_dir($dir_path . '/' . $current . '/' . $file)) {
                    array_push($dirs, $current . '/' . $file);
                } else {
                    if (is_file($dir_path . '/' . $current . '/' . $file) && strpos($file, ".php") > 0) {
                        $path = str_replace(".php", "", $file);
                        $url_maps[CONFIG["app"]["prefix"] . $current . '/' . $path] = $dir_path . "$current/$file";
                    }
                }
            }
        }
    }
    return $url_maps;
}
